<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP技术</title>
<style type="text/css">
html,body,table{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
margin:0;
padding:0;;
}
</style>
<script type="text/javascript">
function ShowMenu(MenuID)
{
if(MenuID.style.display=="none")
{
     MenuID.style.display="";
}
else
{
     MenuID.style.display="none";
}
}

function showUrl(value){
var obj=document.getElementById("content_text");
if(value!=null){
   obj.innerHTML=decodeURIComponent(value);
}
}
</script>
</head>

<body>
    <div align="center"><img src="../MyImage/4.jpg" width="746" height="363" /></div>
    <div style="width:746px; margin:0 auto;">
    <div align="left" style="width:300px; float:left;">
<?php
    $Conn=mysql_connect("localhost","root","root");
mysql_select_db("test"); //打开数据库
mysql_query("SET NAMES 'utf8'"); //避免乱码
$GLOBALS["id"] =1;
$jibie=1;
$sql="select * from menu where parent_id=0";
$result=mysql_query($sql,$Conn);

if(mysql_num_rows($result)>0)
TreeMenu($Conn,$result,$jibie,$id);

function TreeMenu($Conn,$result,$jibie) //进入函数循环
{
$numrows=mysql_num_rows($result);
echo "<table cellpadding='0' cellspacing='0' border='0'>";
for($rows=0;$rows<$numrows;$rows++)
{
$menu=mysql_fetch_array($result);
$sql="select * from menu where parent_id=$menu[id]";
$result_sub=mysql_query($sql,$Conn);
echo "<tr>";
   //如果该菜单项目有子菜单，则添加JavaScript onClick语句
   if(mysql_num_rows($result_sub)>0)
   {
   echo "<td width='20'><img src='+.gif' border='0'></td>";
   echo "<td style='cursor:pointer;' class='Menu' onClick='javascript:ShowMenu(Menu".$GLOBALS["ID"].');showUrl('."\"".rawurlencode($menu["description "])."\"".")'>";
   }
   else
   {
   echo "<td width='20'><img src='-.gif' border='0'></td>";
   echo "<td class='Menu'>";
   }
   if($menu["description" ]!="")
   echo "<a style='cursor:pointer;' onclick='showUrl(\"".rawurlencode($menu["description "])."\")'>$menu[name]</a> ";
   else
   echo "<a style='cursor:pointer;' onclick='showUrl(\"".rawurlencode($menu["description "])."\")'>$menu[name]</a> ";/*<a href='?b={$menu[id]}&tpye=add'> 添加</a> <a href='?b={$menu[id]}&tpye=edit'> 编辑</a> <a href='?b={$menu[id]}&action=del'> 删除</a>;*/
   echo "</td> </tr>";
   if(mysql_num_rows($result_sub)>0)
   {
   echo "<tr id=Menu".$GLOBALS["ID"]++." style='display:none'>";
   echo "<td width='20'> </td>";
   echo "<td>";
   //将级数加1
   $jibie++;
   TreeMenu($Conn,$result_sub,$jibie);
   $jibie--;
   echo "</td></tr>";
   }
   //显示下一菜单
   }
   echo "</table>";
}
?>
</div>
<div style="width:446px; float:left;" id="content_text"><?php  ?></div>
<div style="clear:both;"></div>
</div>
<p>&nbsp;</p>
</body>
</html>